/********************************************************
* @file: PAMWIN.cpp
* @date: 09/09/2009
********************************************************
* acmFrame
********************************************************/

// includes
//----------
#include <stdlib.h> 
#include "pam.h"


// initializations
//-----------------
PAMWIN* PAMWIN::m_pam = NULL;


//
//////////////////////////////////////////////////////////////////////////
PAMWIN::PAMWIN(): 
	m_active     ( false )
, m_objdraw    ( NULL )
, m_endAction  ( NULL )
, m_firstPts ( false )
, m_oldState   ( -1 )
{
}

//
//////////////////////////////////////////////////////////////////////////
PAMWIN::~PAMWIN()
{
//  if( m_objdraw != NULL )
//    delete m_objdraw;
}


//
//////////////////////////////////////////////////////////////////////////
PAMWIN&
PAMWIN::instance()
{
  if( !m_pam )
  {
    m_pam = new PAMWIN();
  }
  return *m_pam;
}


//
//////////////////////////////////////////////////////////////////////////
void
 PAMWIN::setEndAction(void *obj, void (*endAction)(void *obj, double dx, double dy, int old_state))
{
  m_endAction = endAction;
  m_objClass  = obj;
}

//
//////////////////////////////////////////////////////////////////////////
void 
PAMWIN::setDraw ( drawGRA *_obj )
{
  m_objdraw = _obj;
}

//
//////////////////////////////////////////////////////////////////////////
int
PAMWIN::begin (int curr_state)
{
	if (!m_active)
		return 0;
	
  m_firstPts = false;
  m_oldState = curr_state;
  
  return 1;
}

//
//////////////////////////////////////////////////////////////////////////
int 
PAMWIN::addPoint( double _x, double _y)
{
	if (!m_active)
		return 0;
  
  if (!m_firstPts)
  {
  	m_x1 = xtmp = _x; 
  	m_y1 = ytmp = _y;
    m_firstPts = true;
  }
  else  // set second point
  {
    // compute maximum and minimum values
    double dx = m_x1 - _x, dy = m_y1 - _y;
    m_endAction(m_objClass, dx, dy, m_oldState); // create curve

    m_oldState = -1;
    m_firstPts = m_active = false;

  }

  return 1;
}

//
//////////////////////////////////////////////////////////////////////////
int 
PAMWIN::addTempPoint( double _x, double _y )
{
	if (!m_active)
		return 0;

  //double dx = m_x1 - _x, dy = m_y1 - _y;
  //m_endAction(m_objClass, dx, dy, 4); // create curve

  return 1;
}


//
//////////////////////////////////////////////////////////////////////////
void 
PAMWIN::draw()
{
	if (!m_active || !m_firstPts)
		return;


}

